package com.ghck.shop.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.exception.ErrorConstant;
import com.ghck.server.exception.GhckException;
import com.ghck.shop.dao.MakerFlowWaterMapper;
import com.ghck.shop.model.MakerFlowWater;
import com.ghck.shop.service.FlowService;

@Service
@Transactional
public class FlowServiceImpl implements FlowService{

	
	@Autowired
	private MakerFlowWaterMapper makerFlowWaterMapper;
	
	
	@Override
	public Integer addMakerFlowWater(Integer amount,Integer markUserId,Integer userId,Integer orderId) {
		MakerFlowWater makerFlowWater = new MakerFlowWater();
		makerFlowWater.setAmount(amount);
		makerFlowWater.setMakerUserId(markUserId);
		makerFlowWater.setUserId(userId);
		makerFlowWater.setOrderId(orderId);
		makerFlowWaterMapper.addMakerFlowWater(makerFlowWater);
		return makerFlowWater.getId();
	}
	
	@Override
	public MakerFlowWater getMakerFlowWaterByOrderId(Integer orderId) {
		return makerFlowWaterMapper.findMakerFlowWaterByOrderId(orderId);
	}


	@Override
	public void updateMakerFlowWaterAmount(Integer id, Integer amount) {
		
		makerFlowWaterMapper.updateMakerFlowWaterAmount(id, amount);
	}
	
	

	@Override
	public List<MakerFlowWater> getMakerFlowWatersList(Integer userId, Integer start, Integer limit) {
		if(null == userId || userId == 0){
			throw new GhckException(ErrorConstant.PARAM_ERROR.getErrorCode(), "用户ID不能为空");
		}
		if(null == start){
			throw new GhckException(ErrorConstant.PARAM_ERROR.getErrorCode(), "参数start不能为空");
		}
		if(null == limit){
			throw new GhckException(ErrorConstant.PARAM_ERROR.getErrorCode(), "参数limit不能为空");
		}
		return makerFlowWaterMapper.listMakerFlowWaters(userId, start, limit);
	}

	@Override
	public void updateMakerFlowWaterComplete(Integer id) {
		makerFlowWaterMapper.updateMakerFlowWaterComplete(id);
	}

	@Override
	public Integer addFlowWater() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer addShopFlowWater() {
		// TODO Auto-generated method stub
		return null;
	}

}
